package net.sareweb.acab.components;

import java.util.Date;

import net.sareweb.acab.components.session.AcabEvents;
import net.sareweb.acab.components.session.AcabIdentity;
import net.sareweb.acab.entity.User;
import net.sareweb.acab.util.AcabEvent;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.log.Log;

@Name("eventListener")
public class EventListener {
	@Logger
	private Log log;
	@In 
	AcabEvents acabEvents;
	@In 
	AcabIdentity identity;
	
	@Observer("userLoggedEvent")
	public void userLoggedEventObserver() {
		log.info("User logged");
		AcabEvent ev = new AcabEvent();
		ev.setUser(identity.getUser());
		ev.setWhat(" logged in");
		ev.setWhen(new Date());
		ev.setAvatar(identity.getAvatarSmall());
		ev.setEventType(AcabEvent._EVENT_TYPE_LOGIN);
		acabEvents.addEvent(ev);
	}
	
	@Observer("userCreatedEvent")
	public void userCreatedEventObserver(User user) {
		log.info("user created");
		AcabEvent ev = new AcabEvent();
		ev.setUser(user);
		ev.setWhat(" is new User");
		ev.setWhen(new Date());
		ev.setAvatar(null);
		ev.setEventType(AcabEvent._EVENT_TYPE_REGISTER);
		acabEvents.addEvent(ev);
	}
	
	
	@Observer("travelCreatedEvent")
	public void travelCreatedEventObserver() {
		log.info("Travel Created");
		AcabEvent ev = new AcabEvent();
		ev.setUser(identity.getUser());
		ev.setWhat(" Created a new Travel");
		ev.setWhen(new Date());
		ev.setAvatar(identity.getAvatarSmall());
		ev.setEventType(AcabEvent._EVENT_TYPE_TRAVEL_CREATED);
		acabEvents.addEvent(ev);
	}
	
	@Observer("requestMadeEvent")
	public void requestCreatedEventObserver() {
		log.info("Request Created");
		AcabEvent ev = new AcabEvent();
		ev.setUser(identity.getUser());
		ev.setWhat(" Made a Request");
		ev.setWhen(new Date());
		ev.setAvatar(identity.getAvatarSmall());
		ev.setEventType(AcabEvent._EVENT_TYPE_REQUEST_CREATED);
		acabEvents.addEvent(ev);
	}
	
	
	@Observer("seatAsignedEvent")
	public void seatAsignedEventObserver() {
		AcabEvent ev = new AcabEvent();
		ev.setUser(identity.getUser());
		ev.setAvatar(identity.getAvatarSmall());
		ev.setWhat(" Asigned a seat.");
		ev.setWhen(new Date());
		ev.setEventType(AcabEvent._EVENT_TYPE_SEAT_ASIGNED);
		acabEvents.addEvent(ev);
	}
	
	@Observer("seatReleasedEvent")
	public void seatReleasedEventObserver() {
		AcabEvent ev = new AcabEvent();
		ev.setUser(identity.getUser());
		ev.setAvatar(identity.getAvatarSmall());
		ev.setWhat(" Released a seat.");
		ev.setWhen(new Date());
		ev.setEventType(AcabEvent._EVENT_TYPE_SEAT_RELEASED);
		acabEvents.addEvent(ev);
	}



}
